//
//  BuyingViewController.swift
//  BookStore2.0
//
//  Created by hw on 2022/6/1.
//

import UIKit

class BuyingViewController: UIViewController {

    var BookNum:Int=0
    var Price:Float=0
    
    @IBOutlet weak var BuyNum: UILabel!
    
    @IBOutlet weak var TotalPrice: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        BuyNum.text="\(BookNum)"
        TotalPrice.text="\(Price)"
        // Do any additional setup after loading the view.
    }
    @IBAction func payBtn(_ sender: Any) {
        let ordertime=Date()
        let BookNum=ShoppingCart.sharedinstance.getTotalNum()
        let Price=ShoppingCart.sharedinstance.getTotalCost()
        let order=Order(booknumSum:BookNum,moneySum:Price,ordertime:ordertime)
        let result=DB1.insertOrder(order: order)
        let orderID=(result![0]["max(rowid)"] as! NSNumber).intValue
        ShoppingCart.sharedinstance.outputOrderItem(orderid: orderID)
        ShoppingCart.sharedinstance.clearAll()
        let p=UIAlertController(title:"操作成功",message:"购买成功！",preferredStyle:.alert)
        p.addAction(UIAlertAction(title:"确定",style:.default,handler:{
            (
                act:UIAlertAction)in self.performSegue(withIdentifier: "backUnwindsegue", sender:self)
           
        }))
        present(p,animated:false,completion:nil)
    }
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
